
import { computed } from 'vue'
// 手机号脱敏
export const judgePhone = computed(() => {
    return function(val: any) {
        if (!val) return ''
        let reg = /^(.{3}).*(.{4})$/
        console.log('6666', val)
        return val.replace(reg, '$1****$2')
    }
})


// 姓名脱敏
const hideInsurantName = (val: string)  =>{
    if (!val || val === '') return ''
    let name = ''
    if (val.length === 2) {
      name = val.substring(0, 1) + '*' // 截取name 字符串截取第一个字符，
    } else if (val.length === 3) {
      name = val.substring(0, 1) + '*' + val.substring(2, 3) // 截取第一个和第三个字符
    } else if (val.length === 4) {
      name = val.substring(0, 2) + '*' + '*' // 4个字隐藏后面两个
    } else if (val.length > 4) {
      name = val.substring(0, 1) // 5个字只显示第一个字
      for (let i = 0; i < val.length - 1; i++) {
        name = name + '*'
      }
    }
    return name
}

// 身份证脱敏
const judgeCard = (val: string) =>{
    if (!val) return ''
    let reg = /^(.{3}).*(.{2})$/
    return val.replace(reg, '$1*************$2')
}
